package com.room.room.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.room.room.entity.HouseSecondaryEntity;
import com.room.room.service.HouseSecondaryService;
import com.project.utils.PageUtils;
import com.project.utils.R;



/**
 * 
 *
 * @author brh
 * @email sunlightcs@gmail.com
 * @date 2022-03-23 16:10:46
 */
@RestController
@RequestMapping("room/housesecondary")
public class HouseSecondaryController {
    @Autowired
    private HouseSecondaryService houseSecondaryService;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = houseSecondaryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{secondaryId}")
    public R info(@PathVariable("secondaryId") Integer secondaryId){
		HouseSecondaryEntity houseSecondary = houseSecondaryService.getById(secondaryId);

        return R.ok().put("houseSecondary", houseSecondary);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HouseSecondaryEntity houseSecondary){
		houseSecondaryService.save(houseSecondary);
        redisTemplate.boundHashOps("HouseList").delete("SecondList");
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HouseSecondaryEntity houseSecondary){
		houseSecondaryService.updateById(houseSecondary);
        redisTemplate.boundHashOps("HouseList").delete("SecondList");
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] secondaryIds){
		houseSecondaryService.removeByIds(Arrays.asList(secondaryIds));
        redisTemplate.boundHashOps("HouseList").delete("SecondList");
        return R.ok();
    }

}
